/* login-window.c
 *
 * Copyright 2024 wan-iot
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "my-window.h"
//#include <gtk-3.0/gtk/gtk.h>

struct _MyWindow{
  GtkApplicationWindow  parent_instance;
  GtkButton *btn_login; 
  GtkMessageDialog *quit_message;
  GtkButton *btn_yes;
  GtkButton *btn_no;

};

GtkWidget *logout_message;

G_DEFINE_TYPE (MyWindow, my_window, GTK_TYPE_APPLICATION_WINDOW)

static void
my_window_class_init (MyWindowClass *klass)
{
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);

  gtk_widget_class_set_template_from_resource (widget_class, "/a/b/d/my-window.ui");
  gtk_widget_class_bind_template_child (widget_class, MyWindow, quit_message);
  gtk_widget_class_bind_template_child (widget_class, MyWindow, btn_login);
  gtk_widget_class_bind_template_child (widget_class, MyWindow, btn_yes);
  gtk_widget_class_bind_template_child (widget_class, MyWindow, btn_no);
  //注册主窗体
  //gtk_widget_class_bind_template_child (widget_class, MyWindow, main_window);
  //gtk_widget_class_bind_template_child (widget_class, MyWindow, btn_query);
 
}

void query(){
  g_print("easy!\n");
}
gboolean flag = TRUE;
gboolean main_close(){
  g_print("退出主窗体\n");
  gtk_widget_show (logout_message);
  g_print("===%d\n",flag);
  return flag;
}
void selected(GtkButton * btn){
  g_print("yes/no \n");
  char* txt = (gchar*)gtk_button_get_label (btn);
  if(strcmp (txt, "是(Y)")==0){
    g_print("yes\n");
   exit(0);
  }else{
    //flag = FALSE;
    g_print("no==%d\n",flag);
    gtk_widget_hide (logout_message);
    
  }
}

static void
my_window_init (MyWindow *self)
{
  gtk_widget_init_template (GTK_WIDGET (self));
  logout_message = (GtkWidget*)self->quit_message;
  g_signal_connect (self->btn_login, "clicked", G_CALLBACK(query), NULL);
  //单击关闭时
  g_signal_connect (self, "delete_event", G_CALLBACK (main_close), NULL);
  g_signal_connect (self->btn_yes, "clicked", G_CALLBACK (selected), NULL);
  g_signal_connect (self->btn_no, "clicked", G_CALLBACK (selected), NULL);
  
  
}
